clear
use "cps2015.dta"

/*
****Data Cleaning (Done)****
*1. Merge Jan to Dec (Skip)
*2. drop unemployed
drop if prempnot <1 | prempnot >1
*3. Drop races other than white and black
drop if ptdtrace>2
*4. Black indicator
gen black=0
replace black=1 if ptdtrace==2
*5. Education level
gen highsch=0
replace highsch=1 if peeduca==39
gen somecollege=0
replace somecollege=1 if inrange(peeduca,40,42)
gen degree=0
replace degree=1 if peeduca==43
gen postgrad=0
replace postgrad=1 if peeduca>43
*6 Felmale indicator
gen female=0
replace female=1 if pesex==2
*7 union indicator
gen union=0
replace union=1 if peerncov==1
*8 worker class
gen govt=0
replace govt=1 if peio1cow<4
gen selfem=0
replace selfem=1 if inrange(peio1cow,6,7)

*9. quardic age
gen age2=prtage*prtage

*12 earnings
*used
gen hwage=prernwa/pehrusl1
gen lwage=log(hwage)
*OR (not used)
gen lwage = log(prernhly)

*13 merge with license data
gen personid= string(hrmonth) + "-" + qstnum+ "-" + string(pulineno)
gen license=0
replace license=1 if pecert1==1 & pecert2==1
gen cert=0
replace cert=1 if pecert1==1 & pecert2==2

*14 month effects
forvalue m = 1/11{
gen monthfix`m'=0
replace monthfix`m'=1 if hrmonth==`m'
}

*/
************Undone******************

gen service=0
replace service=1 if inrange(prmjind1,8,12)

* drop female, hispanic
drop if female==1 | pehspnon==1

gen str idid=hrhhid+hrhhid2+string(pulineno)

gen state_occ=string(gestfips)+"-"+string(peio1ocd) if license==1

merge m:1 state_occ using "mandatory_unique.dta", generate(_felonymerge)

drop if _felonymerge==2
replace permban=0 if _felonymerge==1

rename permban Ban
label var Ban "Ban"


foreach y in license Ban{
	gen `y'_black=`y'*black
	label var `y'_black "`y'*black"
}


local control prtage age2 govt union highsch somecollege degree postgrad selfem service

keep if prftlf==1 & peio1cow<8 & inrange(prtage,18,64) & inrange(hwage,5,100) 

gen boxyes=0
replace boxyes=1 if inlist(gestfips,6,8,9,11,15,25,27,35)

gen BTBban=Ban*boxyes
replace Ban=0 if BTBban==1
gen nonBTBban=Ban

foreach y in BTBban nonBTBban{
	gen `y'_black=`y'*black
	label var `y'_black "`y'*black"
}

areg lwage black license* BTBban* nonBTBban* cert `control' i.gestfips [aw=pwsswgt], absorb(peio1ocd) vce(cluster gestfips)
outreg2 using Table8.tex, keep(black license* BTBban* nonBTBban*) label
